package com.chenglu.android.restaurant.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.goodsinfo.touch.BigImgActivity;
import com.chenglu.android.restaurant.bean.ShopReviewPageBean;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: lyj
 * @Created: by Copyright 2023 3 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：满减
 */
public class ShopEvaluateAdapter extends BaseQuickAdapter<ShopReviewPageBean.DataBean.RecordsBean, BaseViewHolder> {

    Context mContext;

    public ShopEvaluateAdapter(Context context, @Nullable ArrayList<ShopReviewPageBean.DataBean.RecordsBean> data) {
        super(R.layout.item_shop_evaluate, data);
        this.mContext = context;
    }


    @Override
    protected void convert(@NonNull BaseViewHolder helper, ShopReviewPageBean.DataBean.RecordsBean item) {
        ImageView imageView = helper.getView(R.id.iv_userAvatar);
        RatingBar ratingBar = helper.getView(R.id.ratingBar_goodsReview);
        RecyclerView recyclerView = helper.getView(R.id.rv_reviewImgList);
        recyclerView.setNestedScrollingEnabled(false);
        if (item.getIsAnonymity() == 1) {
            helper.setText(R.id.tv_userNickName, "匿名");
        } else {
            helper.setText(R.id.tv_userNickName, item.getUserNickName());
            Glide.with(mContext).load(item.getUserAvatar()).into(imageView);
        }
        helper.setText(R.id.tv_reviewTime, item.getReviewTime());
        helper.setText(R.id.tv_reviewCntent, item.getReviewCntent());
        ratingBar.setRating(item.getGoodsReview());
        if (item.getReviewImgList().isEmpty()) {
            recyclerView.setVisibility(View.GONE);
        } else {
            recyclerView.setVisibility(View.VISIBLE);
            ArrayList<String> photoList = new ArrayList<>(Arrays.asList(item.getReviewImgList().split(",")));
            ShopStoryListAdapter shopStoryListAdapter = new ShopStoryListAdapter(mContext, photoList);
            recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));
            recyclerView.setAdapter(shopStoryListAdapter);
            shopStoryListAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    switch (view.getId()) {
                        case R.id.iv_item_src:
                            Intent intent = new Intent(mContext, BigImgActivity.class);
                            intent.putStringArrayListExtra("imgData", (ArrayList<String>) photoList);
                            intent.putExtra("clickPosition", position);
                            mContext.startActivity(intent);
                            break;
                    }
                }
            });
        }


    }

}
